//
//  WBNavigationController.swift
//  陌路微博
//
//  Created by 张继强 on 16/12/2.
//  Copyright © 2016年 张继强. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏默认的navgationBar
        self.navigationBar.isHidden = true
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    @objc fileprivate func popToController(){
        self.popViewController(animated: true)
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if self.childViewControllers.count>0{
            viewController.hidesBottomBarWhenPushed = true
            //判断控制器的类型
            if let vc = viewController as?WBBaseViewController{
                var title = "返回"
                if childViewControllers.count == 1{
                   title = childViewControllers.first?.title ?? "返回"
                }
                vc.navIteam.leftBarButtonItem = UIBarButtonItem.init(title: title, fontSize: 16, target: self, action: #selector(popToController), isBack: true)
            }
        }
        super.pushViewController(viewController, animated: animated)
    }
}

